﻿using System;
using System.Web;
using System.Xml;
using System.Xml.Schema;

namespace TestUp.Models.TestWorkers
{
    public class XmlTestValidator
    {
        private static string ValidationShemaLocation
        {
            get { return HttpContext.Current.Server.MapPath("/App_Data/testTemplate.xsd"); }
        }

        public static bool Validate(XmlDocument xmlDocument)
        {
            if (xmlDocument == null)
                return false;

            xmlDocument.Schemas.Add(null, ValidationShemaLocation);
            try
            {
                xmlDocument.Validate(ValidationCallBack);
            }
            catch
            {
                return false;
            }
            return true;
        }

        private static void ValidationCallBack(object sender, ValidationEventArgs e)
        {
            throw new Exception();
        }
    }
}